var banner = document.querySelector(".banner");
var middle = document.querySelector(".middle");
var divs = document.querySelectorAll(".middle>div");
var cirs = document.querySelectorAll(".cir");
var w = banner.offsetWidth;
middle.style.width = w * divs.length + "px";
var page1 = 0;
var timer = null;
timer2 = null;
timer = setInterval(function() {
	page1++;
	if (page1 > divs.length - 1) {
		page1 = 0;
	}
	middle.style.left = -w * page1 + "px";
}, 2000)
timer2 =setInterval(function(){
	for (var i=0;i<cirs.length;i++){
		cirs[i].style.backgroundColor="";
			
	}
		cirs[page1].style.backgroundColor="white";
},2000)


var adv = document.querySelector(".adv");
var ad_middle = document.querySelector(".ad_middle");
var ad_mid_divs = document.querySelectorAll(".ad_middle>div");
var h = adv.offsetHeight;
middle.style.height = h * ad_mid_divs.length + "px";
var page2 = 0;
var timer3 = null;
timer3 = setInterval(function() {
	page2++;
	if (page2 > ad_mid_divs.length - 1) {
		page2 = 0;
	}
	ad_middle.style.top = -h * page2 + "px";
}, 3000)
var class_tits= document.querySelectorAll(".class_tit>div");
var info_items = document.querySelectorAll(".info_item>div");
var info_conts = document.querySelectorAll(".info_cont>div");
var class_conts = document.querySelectorAll(".class_cont>div")
var class_cont_img=document.querySelectorAll(".class_cont_img")
for (var i = 0;i<class_tits.length;i++) {
	class_tits[i].index = i;
	class_tits[i].onclick = function(){
		for (var j = 0;j<class_tits.length;j++) {
			class_tits[j].style.color="#CCCCCC";
			class_conts[j].style.display="none";
		}
		this.style.color="#EC1925";
		class_conts[this.index].style.display = "block";
	}
}
for (var i=0;i<info_items.length;i++) {
	info_items[i].index=i;
	info_items[i].onclick = function(){
		for (var j=0;j<info_items.length;j++) {
			info_items[j].style.color="";
			info_conts[j].style.display="none";
		}
		this.style.color="#EC1925";
		info_conts[this.index].style.display="block";
	}
}

var deals = document.querySelectorAll(".deal");
for(var i=0;i<deals.length;i++){
	deals[i].index=i+1;
	deals[i].onclick=function(){
		
		for (var j=0;j<deals.length;j++) {
			var a=j+1;
			deals[j].src="img/mo_gradu/deal_uncli"+a+".png";
		}
		this.src="img/mo_gradu/deal_cli"+this.index+".png"
	}
}

$(".pri_more").click(function(){
	if ( $("#k_frame").css('display') =='none'){
		$(".pri_more").text('收起');
		$("#k_frame").css('display','block').attr('src','http://192.168.99.201:8090/?UUId=45c98d9a-6931-4dce-93c1-4d7228af5ba9&UserId=0&TimesTamp=1472548615560&Token=KrlnuzICn7qEN%2BpQUDhv%2FZ8Re5w%2FSug7uoOSr6QLW9R9D4pnzbFcyPzLyVGx2bSj3%2FONSE2iN4EAVr7a0OvSfw%3D%3D&Signature=hS%2FKBiwqzlk17Gz2%2FNxwnAlr%2BVweD2%2BoPnyIutv7OuLsDyp27hMZLztrudrfyMiEMdObbNuMZ11SJruAytgX%2BQ%3D%3D&AppName=MOBILECLIENT&MobileType=1&Code='+$("#mySelect").val());
	}else{
		$("#k_frame").css('display','none');
		$(".pri_more").text('更多');
	}
});

/*EventSource & K线 9.23 JackYan*/
//var ws=new WebSocket("ws://192.168.99.201:8082");
var ws=new WebSocket("ws://121.196.194.185:8025");  //正式服务器的线上WebStock地址。
ws.onmessage=function(event){
    var items=JSON.parse(event.data);
    var nowSelected=$("#mySelect").val();
    console.log(items);
    console.log('正在接受WebStock，当前产品号：'+nowSelected);
	for(var i=0;i<items.length;i++){
		if(items[i].ProductCode==nowSelected){
			if(items[i].UpOrDownRate>0){//涨了
				$("#sell,#upOrDown,#upOrDownRate").css('color','#ec1925'); //红色
				$("#sell").text(items[i].Sell.toFixed(1));		
				$("#upOrDown").text("+"+items[i].UpOrDown.toFixed(1));	
				$("#upOrDownRate").text("+"+items[i].UpOrDownRate+"%");
				
			}else{//跌了
				$("#sell,#upOrDown,#upOrDownRate").css('color','#1fc435'); //绿色
				$("#sell").text(items[i].Sell);		
				$("#upOrDown").text(items[i].UpOrDown);
				$("#upOrDownRate").text(items[i].UpOrDownRate+"%");
			}
				
			$("#openPrice").text(items[i].OpenPrice);
			$("#lastClose").text(items[i].LastClose);
			$("#high").text(items[i].High);
			$("#low").text(items[i].Low);
		}
	}
//	console.log(JSON.parse(event.data));
}
/*下拉选框绑定K线图事件--9.23--JackYan*/
$("#mySelect").change(function(){
	$("#k_frame").attr('src','http://192.168.99.201:8090/?UUId=45c98d9a-6931-4dce-93c1-4d7228af5ba9&UserId=0&TimesTamp=1472548615560&Token=KrlnuzICn7qEN%2BpQUDhv%2FZ8Re5w%2FSug7uoOSr6QLW9R9D4pnzbFcyPzLyVGx2bSj3%2FONSE2iN4EAVr7a0OvSfw%3D%3D&Signature=hS%2FKBiwqzlk17Gz2%2FNxwnAlr%2BVweD2%2BoPnyIutv7OuLsDyp27hMZLztrudrfyMiEMdObbNuMZ11SJruAytgX%2BQ%3D%3D&AppName=MOBILECLIENT&MobileType=1&Code='+$("#mySelect").val());
});
